<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    function array(p) {
      const dp = new Array(26).fill(0)
      let arr = 1
      // 返回指定的字符的编码
      dp[p.charCodeAt(0) - 'a'.charCodeAt(0)] = 1
      for (let i = 1; i < p.length; i++) {
        if ((p.charCodeAt(i) - p.charCodeAt(i - 1) + 25) % 26 == 0) {
          arr++
        } else {
          arr = 1
        }
        const res = p.charCodeAt(i) - 'a'.charCodeAt(0)
        dp[res] = Math.max(dp[res], arr)
      }
      return dp.reduce((a, b) => a + b)
    };
    console.log(array("zab"));
  </script>

</body>

</html>